"""
    Entry for ATS, start you can start all service thread in this module.
    Created by Ivy.Li 2013.04.11.
    (C)Copyright 2013 Hech. All rights reserved
"""

import sys
import os
from ATS.util import constant
import socket
import configparser as ConfigParser
from ATS.hardwarescan import conf_file_manager
from ATS.socketServer import SocketServer

sys.path.insert(0, os.path.dirname(os.getcwd()))
# 获得主机的ip地址
myipaddr = socket.gethostbyname(socket.gethostname())
file_name = os.path.join(constant.GUI_PATH, 'GUI_Setting.ini')
config = ConfigParser.ConfigParser()
config.read(file_name)
# config.set("ATS", "ip", myipaddr)
with open(file_name, "w") as f:
    config.write(f)

if constant.build:
    f_dir = os.path.join(constant.ATS_PATH, 'Exceptions.myLog')
    sys.stdout = open(f_dir, 'w', 0)
    sys.stderr = open(f_dir, 'w', 0)

workpath = os.path.dirname(os.path.realpath(sys.argv[0]))
sys.path.insert(0, os.path.dirname(workpath))
sys.path.append(constant.ATS_PATH)

if __name__ == '__main__':
    # 获得配置文件中的信息
    conf_file_manager.getinstconfig()
    # logger.get_logger().start()
    server = SocketServer.SocketServer()
